package com.spa.infrastructure.repository.service;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.spa.infrastructure.repository.condition.MassagistEvaluateCondition;
import com.spa.infrastructure.repository.mapper.MassagistEvaluateMapper;
import com.spa.infrastructure.repository.po.MassagistEvaluatePO;
import com.spa.infrastructure.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
public class MassagistEvaluateRepositoryService extends MPJBaseServiceImpl<MassagistEvaluateMapper, MassagistEvaluatePO> {

    /**
     * 分页
     *
     * @author: lig
     * @date: 2024-01-08
     */
    public Page<MassagistEvaluatePO> pageListInfo(MassagistEvaluateCondition condition) {
        LambdaQueryWrapper<MassagistEvaluatePO> wrapper = wrapper(condition);
        return page(Page.of(condition.getCurrent(), condition.getSize()), wrapper);

    }

    public List<MassagistEvaluatePO> listInfo(MassagistEvaluateCondition condition) {
        return list(wrapper(condition));

    }

//    public MassagistEvaluatePO info(MassagistEvaluateCondition condition) {
//        return getOne(wrapper(condition));
//
//    }

    private LambdaQueryWrapper<MassagistEvaluatePO> wrapper(MassagistEvaluateCondition condition) {
        LambdaQueryWrapper<MassagistEvaluatePO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getMassagistId()), MassagistEvaluatePO::getMassagistId, condition.getMassagistId());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getOrderId()), MassagistEvaluatePO::getOrderId, condition.getOrderId());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getUserId()), MassagistEvaluatePO::getUserId, condition.getUserId());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getSatisfaction()), MassagistEvaluatePO::getIsSatisfaction, condition.getSatisfaction());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getScore()), MassagistEvaluatePO::getScore, condition.getScore());
        wrapper.in(CollUtil.isNotEmpty(condition.getInScore()), MassagistEvaluatePO::getScore, condition.getInScore());
        wrapper.in(ObjectUtils.isNotEmpty(condition.getMassagistIds()), MassagistEvaluatePO::getMassagistId, condition.getMassagistIds());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getIsDel()), MassagistEvaluatePO::getIsDel, condition.getIsDel());

        wrapper.gt(StringUtils.isNotEmpty(condition.getBeginTime()), MassagistEvaluatePO::getCreateTime, condition.getBeginTime());
        wrapper.lt(StringUtils.isNotEmpty(condition.getEndTime()), MassagistEvaluatePO::getCreateTime, condition.getEndTime());

        wrapper.orderByDesc(MassagistEvaluatePO::getCreateTime);
        return wrapper;
    }


    public boolean addInfo(MassagistEvaluatePO po) {
        return save(po);
    }


}
